# -*- coding: utf-8 -*-
import logging.config
from repoze.bfg.router import make_app
from repoze.zodbconn.finder import PersistentApplicationFinder

def app(global_config, **kw):
    """
    Create WSGI application.
    """
    zodb_uri = kw.get('zodb_uri')
    if zodb_uri is None:
        raise ValueError("No 'zodb_uri' in application configuration.")
    
    if 'logging_config' in kw:
        logging.config.fileConfig(kw['logging_config'])

    import pargo
    from pargo.content import appmaker
    
    get_root = PersistentApplicationFinder(zodb_uri, appmaker)
    return make_app(get_root, pargo, options=kw)
